package com.example.feishumsg.task;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <h1>  <h1>
 *
 * @author wry
 * @since 2023/10/31 9:30
 */
@RestController
public class HealthController {

    private static final Logger log = LoggerFactory.getLogger(HealthController.class);

    @GetMapping("health")
    public String Health(){
        log.info("app health~");
        return "health";
    }

    @GetMapping("send")
    public String send(@RequestParam("msg") String msg){
        Map<String, Object> json = new HashMap<>();
        Map<String, Object> text = new HashMap<>();
        json.put("msg_type", "text");
        text.put("text",msg);
        json.put("content", text);
        //发送post请求
        return HttpRequest.post("https://open.feishu.cn/open-apis/bot/v2/hook/0ec8182f-5798-4d1f-9df0-583847a7f463").body(JSON.toJSONString(json), "application/json;charset=UTF-8").execute().body();
    }
}
